package studychinese.utils;

import android.widget.TextView;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by zf on 2018/1/9.
 */

public class TimeUtil  {

    // String data 转换秒
    public static long StringToTime(String data) throws ParseException {

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(data));
        return  calendar.getTimeInMillis()/1000;
    }
//毫秒转换成日期时间字符串
    public void test() {
        long millisecond = 1483159625851l;
        Date date = new Date(millisecond);
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日 hh:mm:ss SSS a");
        System.out.println("毫秒[1483159625851]对应日期时间字符串：" + format.format(date));
    }

    //毫秒转换成日期时间字符串
    public static String Tests(Long time) {
        Date date = new Date(time*1000);
        SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");

        String format1 = format.format(date);
        return format1;
    }
    //毫秒转换成日期时间字符串
    public static String Tests1(Long time) {
        Date date = new Date(time*1000);
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");

        String format1 = format.format(date);
        return format1;
    }

    /**
     * get current time in milliseconds
     *
     * @return
     */
    public static long getCurrentTimeInLong() {
        return System.currentTimeMillis();

    }

    //判断男女
    public  static void PdSex(String sex, TextView textView)
    {
        if (sex.equals("1"))
        {
            textView.setText("男");
        }
        else if (sex.equals("2"))
        {
            textView.setText("女");
        }
        else
        {
            textView.setText("没有这个选项");
        }
    }
    //插入字符
    public  static void  SetAge(String date,TextView textView)
    {
        StringBuilder sb = new StringBuilder(date);
        sb.insert(4,"年");
        sb.insert(7,"月");
        sb.insert(10,"日");
        textView.setText(sb);
    }
}

